#define _CRT_SECURE_NO_WARNINGS 1

#include <vector>
#include <stack>
using namespace std;

struct TreeNode {
     int val;
     TreeNode *left;
     TreeNode *right;
     TreeNode() : val(0), left(nullptr), right(nullptr) {}
     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
class Solution {
public:
    vector<int> inorderTraversal(TreeNode* root) {
        TreeNode* pcur = root;
        vector<int> v;
        stack<TreeNode*> st;
        while (pcur || !st.empty())
        {
            while (pcur)
            {
                st.push(pcur);
                pcur = pcur->left;
            }
            pcur = st.top();
            v.push_back(pcur->val);
            pcur = pcur->right;
            st.pop();
        }
        return v;
    }
};